package cn.tedu.system.review.controller;

import cn.tedu.system.base.response.JsonResult;
import cn.tedu.system.review.pojo.dto.*;
import cn.tedu.system.review.pojo.vo.ReviewSelectVO;
import cn.tedu.system.review.service.ReviewService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Api(tags = "06.评价模块")
@RestController
@RequestMapping("/api/v1/review/")
public class ReviewController {
    @Autowired
    private ReviewService reviewService;

    @ApiOperation("用户评价商品功能")
    @ApiOperationSupport(order = 10)
    @PostMapping("addReview")
    public JsonResult addReview(@RequestBody ReviewAddDto reviewAddDto, @ApiIgnore HttpSession session) {
        log.debug("用户评价参数:{}", reviewAddDto);
        reviewService.addReview(reviewAddDto, session);
        return JsonResult.ok();
    }

    @ApiOperation("用户评价删除功能")
    @ApiOperationSupport(order = 20)
    @PostMapping("delReview")
    public JsonResult deleteReview(@RequestBody Long productId, @ApiIgnore HttpSession session){
        log.debug("用户评价删除:{}", productId);
        reviewService.deleteReview(productId, session);
        return JsonResult.ok();
    }

    @ApiOperation("商家回复评价功能")
    @ApiOperationSupport(order = 30)
    @PostMapping("replayReview")
    public JsonResult replyReview(@RequestBody ReviewReplayDto reviewReplayDto, @ApiIgnore HttpSession session){
        log.debug("商家回复参数:{}", reviewReplayDto);
        reviewService.replyReview(reviewReplayDto,session);
        return JsonResult.ok();
    }

    @ApiOperation("商家删除回复功能")
    @ApiOperationSupport(order = 40)
    @PostMapping("delMerReview")
    public JsonResult delMerReview(@RequestBody ReviewMerDelDto reviewMerDelDto, @ApiIgnore HttpSession session){
        log.debug("商家删除回复:{}", reviewMerDelDto);
        reviewService.delMerReview(reviewMerDelDto,session);
        return JsonResult.ok();
    }

    @ApiOperation("用户评价修改功能")
    @ApiOperationSupport(order = 50)
    @PostMapping("reviewUpdate")
    public JsonResult updateReview(@RequestBody ReviewUpdateDto reviewUpdateDto, @ApiIgnore HttpSession session){
        log.debug("用户评价修改参数:{}", reviewUpdateDto);
        reviewService.updateReview(reviewUpdateDto, session);
        return JsonResult.ok();
    }

    @ApiOperation("商家评价修改功能")
    @ApiOperationSupport(order = 60)
    @PostMapping("merReviewUpdate")
    public JsonResult updateReview2(@RequestBody ReviewMerUpdateDto reviewMerUpdateDto, @ApiIgnore HttpSession session){
        log.debug("商家回复修改参数:{}", reviewMerUpdateDto);
        reviewService.merUpdateReview(reviewMerUpdateDto, session);
        return JsonResult.ok();
    }

    @ApiOperation("显示评价功能")
    @ApiOperationSupport(order = 70)
    @GetMapping("public/review_select")
    public JsonResult selectReview(Long productId,@ApiIgnore HttpSession session){
        List<ReviewSelectVO> list = reviewService.selectReview(productId,session);
        return JsonResult.ok(list);
    }
}
